Are `break` and `continue` bad programming practices?

Posted by Mikhail on Programmers See other posts from Programmers or by Mikhail
Published on 2011-03-15T14:53:07Z Indexed on 2011/03/16 0:17 UTC
Read the original article Hit count: 639

Filed under:
|

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops.

I use them all the time because they make sense; let me show you the inspiration:

function verify(object) {
    if (object->value < 0) return false;
    if (object->value > object->max_value) return false;
    if (object->name == "") return false;
    ...
}

The point here is that first the function checks that the conditions are correct, then executes the actual functionality. IMO same applies with loops:

while (primary_condition) {
    if (loop_count > 1000) break;
    if (time_exect > 3600) break;
    if (this->data == "undefined") continue;
    if (this->skip == true) continue;
    ...
}

I think this makes it easier to read & debug; but I also don't see a downside. Please comment.

© Programmers or respective owner

Related posts about syntax

Related posts about control-structures